package cn.demoncat.util.web.entity;

import org.apache.commons.lang3.StringUtils;

import cn.demoncat.util.lang.StringUtil;
import cn.demoncat.util.lang.constant.StringConstant;
import cn.demoncat.util.web.constant.IpConstant;

/**
 * 手机-地区
 * 
 * @author 延晓磊
 *
 * @since 2020年5月7日
 */
public class MobileRegion {

	// 国家
	private String country;
	// 省
	private String province;
	// 市
	private String city;
	// 地址编码
	private String code;
	// 运营商
	private String isp;
	
	/**
	 * 未知/国外
	 */
	public static final MobileRegion UNKNOWN = new MobileRegion(IpConstant.COUNTRY_TEXT_UNKNOWN, StringConstant.EMPTY, StringConstant.EMPTY, StringConstant.EMPTY);
	
	/**
	 * 国内电话
	 * 
	 * @param province
	 * @param city
	 * @param isp
	 * @return
	 * 
	 * @author 延晓磊
	 *
	 * @since 2020年5月7日
	 */
	public static MobileRegion buildInland(String province, String city, String isp) {
		return new MobileRegion(IpConstant.COUNTRY_TEXT_CN, province, StringUtil.toEmpty(city), isp);
	}
	
	/**
	 * 获取地址名称
	 * 
	 * @return
	 * 
	 * @author 延晓磊
	 *
	 * @since 2020年5月7日
	 */
	public String toAddr() {
		if (IpConstant.COUNTRY_TEXT_CN.equals(country)) {
			// 国内：省[市]
			return StringUtils.isBlank(this.city) ? this.province : this.province + StringConstant.SPACING + this.city;
		}else {
			// 未知/国外：国[省]
			return StringUtils.isBlank(this.province) ? this.country : this.country + StringConstant.SPACING + this.province;
		}
	}
	
	public MobileRegion() {
		super();
	}
	
	public MobileRegion(String country, String province, String city, String isp) {
		this(country, province, city, StringConstant.EMPTY, isp);
	}
	
	public MobileRegion(String country, String province, String city, String code, String isp) {
		super();
		this.country = country;
		this.province = province;
		this.city = city;
		this.code = code;
		this.isp = isp;
	}

	public String getCountry() {
		return country;
	}
	public void setCountry(String country) {
		this.country = country;
	}
	public String getProvince() {
		return province;
	}
	public void setProvince(String province) {
		this.province = province;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getIsp() {
		return isp;
	}

	public void setIsp(String isp) {
		this.isp = isp;
	}
	
	
}
